{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# include(\"../hopfield.jl\")\n",
    "include(\"DevDesc.jl\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "d = Dict{String, Vector{Float64}}()\n",
    "# for i in 1:15\n",
    "#   d[String(\"l$(i)\")] = rand(2)\n",
    "# end\n",
    "for i in 1:30\n",
    "  d[String(\"l$(i)\")] = (3.0.*rand(2))-1\n",
    "end\n",
    "\n",
    "# draw points\n",
    "pl=plot(drawLandmPtsLayer(d))\n",
    "\n",
    "R = 0.5\n",
    "Mf = 4\n",
    "angBins=6\n",
    "rangeBins = 4\n",
    "K=4 # nubmer of features to try\n",
    "bLbls, bestDescr = bestDescriptors(d, r=R, Mf=Mf, k=K, angBins=angBins, rangeBins=rangeBins )\n",
    "\n",
    "if length(bLbls) >= 3\n",
    "    v1 = bestDescr[bLbls[1]]\n",
    "    v2 = bestDescr[bLbls[2]]\n",
    "    v3 = bestDescr[bLbls[3]]\n",
    "    @show hamming(v1,v2)\n",
    "    @show hamming(v1,v3)\n",
    "    @show hamming(v2,v3)\n",
    "    P = [v1';v2';v3']'\n",
    "    P = map(Float64,P)\n",
    "\n",
    "    fm=findMatches(d, P, bLbls, R=R, angBins=angBins, rangeBins=rangeBins, Mf=Mf)\n",
    "    # [@show fm[i] for i in 1:length(fm)]\n",
    "    mmlst = convertToMMLst(fm, floor(Int, length(v1)))\n",
    "    [@show l for l in mmlst]\n",
    "\n",
    "    # draw so we can see\n",
    "    for lm in bLbls\n",
    "    #   push!(pl,circLayer(d[lm],r=R)[1])\n",
    "        rd = findInRadius(d,lm,r=R)\n",
    "        drawDictLinesLayers(pl, rd, lm)\n",
    "    end\n",
    "else\n",
    "    warn(\"not enough description available\")\n",
    "end\n",
    "pl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "\n",
    "errNoise = 0.04*R\n",
    "\n",
    "dd = deepcopy(d)\n",
    "# @show length(d)\n",
    "for i in 1:length(d)\n",
    "    dd[String(\"l$(i)\")] = dd[String(\"l$(i)\")] + errNoise*randn(2) \n",
    "end\n",
    "for i in length(d):floor(Int,length(d)*1.1)\n",
    "  dd[String(\"l$(i)\")] = (3.0*rand(2))-1.0 \n",
    "end\n",
    "\n",
    "fm=findMatches(dd, P, bLbls, R=R, angBins=angBins, rangeBins=rangeBins, Mf=Mf)\n",
    "# [@show fm[i] for i in 1:length(fm)]\n",
    "mmlst = convertToMMLst(fm, floor(Int, length(v1)/3+0.5))\n",
    "[@show l for l in mmlst];"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "pl2 = deepcopy(pl)\n",
    "l2 = drawLandmPtsLayer(dd,c=\"red\")\n",
    "push!(pl2.layers, l2[1])\n",
    "pl2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "@show bLbls\n",
    "v1 = bestDescr[bLbls[1]]\n",
    "v2 = bestDescr[bLbls[2]]\n",
    "v3 = bestDescr[bLbls[3]]\n",
    "# v4 = bestDescr[bLbls[4]]\n",
    "# v5 = bestDescr[bLbls[5]]\n",
    "\n",
    "P = [v1';v2';v3']'\n",
    "# P = [v1';v2';v3';v4']'\n",
    "P = map(Float64,P)\n",
    "\n",
    "@show hamming(v1,v2)\n",
    "@show hamming(v1,v3)\n",
    "@show hamming(v2,v3)\n",
    "\n",
    "# @show hamming(v1,v4)\n",
    "# @show hamming(v2,v4)\n",
    "# @show hamming(v3,v4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "searchHopfield(P,map(Float64,bestDescr[\"l11\"]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "mmlst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "length(v1)/4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.5",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
